clear, close, clc

a = 0;
b = 10;
dx = 0.001;
x = a:dx:b;
f = sin(x);

n = length(x);

% left
areaLR = 0;
for i=1:n-1
    areaLR = areaLR + dx*f(i);
end

% right
areaRR = 0;
for i=1:n-1
    areaRR = areaRR + dx*f(i+1);
end

% trapezoidal
areaTR = 0;
for i=1:n-1
    areaTR = areaTR + dx/2 *(f(i)+f(i+1));
end

%trapz(x,f)
%dx * trapz(f)
%quad(@(xdummy)spline(x,f,xdummy),a,b)

